package com.szly.phm.admin.controller;

import com.szly.phm.admin.aspectj.annotation.OperationLogAnnotation;
import com.szly.phm.admin.aspectj.enums.ModuleEnum;
import com.szly.phm.admin.aspectj.enums.OperationActionEnum;
import com.szly.phm.admin.utils.CustomResponse;
import com.szly.phm.admin.utils.SecurityUtils;
import com.szly.phm.common.entity.dto.ta.*;
import com.szly.phm.common.entity.dto.user.LoginUserDTO;
import com.szly.phm.common.entity.result.RootResponse;
import com.szly.phm.common.service.ITaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
@RestController
@Validated
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@RequestMapping("/pc/radar")
@Api(tags = "任务管理")
public class TaController {
    private final ITaService iTaService;
    @ApiOperation(value = "查询寿命件模型")
    @GetMapping("/v1/LifeModel")
    @CustomResponse
    public RootResponse selectLifeModel(@NotBlank(message = "Id不能为空") @RequestParam(value = "keyPartsModelId") String keyPartsModelId) {
        return iTaService.selectLifeModel(keyPartsModelId);
    }
    @ApiOperation(value = "查询寿命件模型的寿命预测")
    @GetMapping("/v1/LifePieceModel")
    @CustomResponse
    public RootResponse selectLifePieceModel(@Valid LifePieceModelDTO lifePieceModelDTO) {
        return iTaService.selectLifePieceModel(lifePieceModelDTO);
    }

    @ApiOperation(value = "寿命预测")
    @GetMapping("/v1/lifePrediction")
    @CustomResponse
    public RootResponse selectLifePrediction(@NotBlank(message = "Id不能为空") @RequestParam(value = "radarId") String radarId) {
        return iTaService.selectLifePrediction(radarId);
    }

    @ApiOperation(value = "添加专家知识库")
    @OperationLogAnnotation(getModuleName = ModuleEnum.TK_CODE,getOperationAction = OperationActionEnum.SAVE)
    @PostMapping("/v1/taExpertKnowledgeLibrarys")
    @CustomResponse
    public RootResponse createTaExpertKnowledgeLibrarys(@Valid @RequestBody CreateTaExpertKnowledgeLibrarysDTO createMajorDTO) {
        var loginUser = SecurityUtils.getLoginUser();
        var userDTO = new LoginUserDTO();
        userDTO.setUsername(loginUser.getUsername());
        return iTaService.createTaExpertKnowledgeLibrarys(createMajorDTO,userDTO);
    }
    @ApiOperation(value = "查询专家知识库")
    @GetMapping("/v1/taExpertKnowledgeLibrarys")
    @CustomResponse
    public RootResponse selectTaExpertKnowledgeLibrarys(@Valid TaExpertKnowledgeLibrarysPageDTO serverAreaPageDTO) {
        return iTaService.selectTaExpertKnowledgeLibrarys(serverAreaPageDTO);
    }

    @ApiOperation(value = "删除专家知识库")
    @OperationLogAnnotation(getModuleName = ModuleEnum.TK_CODE,getOperationAction = OperationActionEnum.UPDATE)
    @DeleteMapping("/v1/taExpertKnowledgeLibrarys")
    @CustomResponse
    public RootResponse deleteTaExpertKnowledgeLibrarys(@NotBlank(message = "Id不能为空") @RequestParam(value = "id") String id) {
        var loginUser = SecurityUtils.getLoginUser();
        var userDTO = new LoginUserDTO();
        userDTO.setUsername(loginUser.getUsername());
        return iTaService.deleteTaExpertKnowledgeLibrarys(id,userDTO);
    }

    @ApiOperation(value = "修改专家知识库")
    @OperationLogAnnotation(getModuleName = ModuleEnum.TK_CODE,getOperationAction = OperationActionEnum.UPDATE)
    @PutMapping("/v1/taExpertKnowledgeLibrarys")
    @CustomResponse
    public RootResponse updateTaExpertKnowledgeLibrarys(@Valid @RequestBody UpdateTaExpertKnowledgeLibrarysDTO updateRaServerTypes) {
        var loginUser = SecurityUtils.getLoginUser();
        var userDTO = new LoginUserDTO();
        userDTO.setUsername(loginUser.getUsername());
        return iTaService.updateTaExpertKnowledgeLibrarys(updateRaServerTypes,userDTO);
    }



    @ApiOperation(value = "添加智能库")
    @OperationLogAnnotation(getModuleName = ModuleEnum.TK_CODE,getOperationAction = OperationActionEnum.SAVE)
    @PostMapping("/v1/taIntelligenceLibrarys")
    @CustomResponse
    public RootResponse createTaIntelligenceLibrarys(@Valid @RequestBody CreateTaIntelligenceLibrarysDTO createMajorDTO) {
        var loginUser = SecurityUtils.getLoginUser();
        var userDTO = new LoginUserDTO();
        userDTO.setUsername(loginUser.getUsername());
        return iTaService.createTaIntelligenceLibrarys(createMajorDTO,userDTO);
    }
    @ApiOperation(value = "查询智能库")
    @GetMapping("/v1/taIntelligenceLibrarys")
    @CustomResponse
    public RootResponse selectTaIntelligenceLibrarys(@Valid TaIntelligenceLibrarysPageDTO serverAreaPageDTO) {
        return iTaService.selectTaIntelligenceLibrarys(serverAreaPageDTO);
    }

    @ApiOperation(value = "删除智能库")
    @OperationLogAnnotation(getModuleName = ModuleEnum.TK_CODE,getOperationAction = OperationActionEnum.UPDATE)
    @DeleteMapping("/v1/taIntelligenceLibrarys")
    @CustomResponse
    public RootResponse deleteTaIntelligenceLibrarys(@NotBlank(message = "Id不能为空") @RequestParam(value = "id") String id) {
        var loginUser = SecurityUtils.getLoginUser();
        var userDTO = new LoginUserDTO();
        userDTO.setUsername(loginUser.getUsername());
        return iTaService.deleteTaIntelligenceLibrarys(id,userDTO);
    }

    @ApiOperation(value = "修改智能库")
    @OperationLogAnnotation(getModuleName = ModuleEnum.TK_CODE,getOperationAction = OperationActionEnum.UPDATE)
    @PutMapping("/v1/taIntelligenceLibrarys")
    @CustomResponse
    public RootResponse updateTaIntelligenceLibrarys(@Valid @RequestBody UpdateTaIntelligenceLibrarysDTO updateRaServerTypes) {
        var loginUser = SecurityUtils.getLoginUser();
        var userDTO = new LoginUserDTO();
        userDTO.setUsername(loginUser.getUsername());
        return iTaService.updateTaIntelligenceLibrarys(updateRaServerTypes,userDTO);
    }



    @ApiOperation(value = "添加算法库")
    @OperationLogAnnotation(getModuleName = ModuleEnum.TK_CODE,getOperationAction = OperationActionEnum.SAVE)
    @PostMapping("/v1/taAlgorithmlLibrarys")
    @CustomResponse
    public RootResponse createTaAlgorithmlLibrarys(@Valid @RequestBody CreateTaAlgorithmlLibrarysDTO createMajorDTO) {
        var loginUser = SecurityUtils.getLoginUser();
        var userDTO = new LoginUserDTO();
        userDTO.setUsername(loginUser.getUsername());
        return iTaService.createTaAlgorithmlLibrarys(createMajorDTO,userDTO);
    }
    @ApiOperation(value = "查询算法库")
    @GetMapping("/v1/taAlgorithmlLibrarys")
    @CustomResponse
    public RootResponse selectTaAlgorithmlLibrarys(@Valid TaAlgorithmlLibrarysPageDTO serverAreaPageDTO) {
        return iTaService.selectTaAlgorithmlLibrarys(serverAreaPageDTO);
    }

    @ApiOperation(value = "删除算法库")
    @OperationLogAnnotation(getModuleName = ModuleEnum.TK_CODE,getOperationAction = OperationActionEnum.UPDATE)
    @DeleteMapping("/v1/taAlgorithmlLibrarys")
    @CustomResponse
    public RootResponse deleteTaAlgorithmlLibrarys(@NotBlank(message = "Id不能为空") @RequestParam(value = "id") String id) {
        var loginUser = SecurityUtils.getLoginUser();
        var userDTO = new LoginUserDTO();
        userDTO.setUsername(loginUser.getUsername());
        return iTaService.deleteTaAlgorithmlLibrarys(id,userDTO);
    }

    @ApiOperation(value = "修改算法模型库")
    @OperationLogAnnotation(getModuleName = ModuleEnum.TK_CODE,getOperationAction = OperationActionEnum.UPDATE)
    @PutMapping("/v1/taAlgorithmlLibrarys")
    @CustomResponse
    public RootResponse updateTaAlgorithmlLibrarys(@Valid @RequestBody UpdateTaAlgorithmlLibrarysDTO updateRaServerTypes) {
        var loginUser = SecurityUtils.getLoginUser();
        var userDTO = new LoginUserDTO();
        userDTO.setUsername(loginUser.getUsername());
        return iTaService.updateTaAlgorithmlLibrarys(updateRaServerTypes,userDTO);
    }

    @ApiOperation(value = "添加算法模型库")
    @CustomResponse
    @OperationLogAnnotation(getModuleName = ModuleEnum.TK_CODE,getOperationAction = OperationActionEnum.SAVE)
    @PostMapping("/v1/taAlgorithmModelLibrarys")
    public RootResponse createTaAlgorithmModelLibrarys(@Valid @RequestBody CreateTaAlgorithmModelLibrarysDTO createMajorDTO) {
        var loginUser = SecurityUtils.getLoginUser();
        var userDTO = new LoginUserDTO();
        userDTO.setUsername(loginUser.getUsername());
        return iTaService.createTaAlgorithmModelLibrarys(createMajorDTO,userDTO);
    }
    @ApiOperation(value = "查询算法模型库")
    @GetMapping("/v1/taAlgorithmModelLibrarys")
    @CustomResponse
    public RootResponse selectTaAlgorithmModelLibrarys(@Valid TaAlgorithmModelLibrarysPageDTO serverAreaPageDTO) {
        return iTaService.selectTaAlgorithmModelLibrarys(serverAreaPageDTO);
    }

    @ApiOperation(value = "删除算法模型库")
    @OperationLogAnnotation(getModuleName = ModuleEnum.TK_CODE,getOperationAction = OperationActionEnum.UPDATE)
    @DeleteMapping("/v1/taAlgorithmModelLibrarys")
    @CustomResponse
    public RootResponse deleteTaAlgorithmModelLibrarys(@NotBlank(message = "Id不能为空") @RequestParam(value = "id") String id) {
        var loginUser = SecurityUtils.getLoginUser();
        var userDTO = new LoginUserDTO();
        userDTO.setUsername(loginUser.getUsername());
        return iTaService.deleteTaAlgorithmModelLibrarys(id,userDTO);
    }

    @ApiOperation(value = "修改算法模型库")
    @OperationLogAnnotation(getModuleName = ModuleEnum.TK_CODE,getOperationAction = OperationActionEnum.UPDATE)
    @PutMapping("/v1/taAlgorithmModelLibrarys")
    @CustomResponse
    public RootResponse updateTaAlgorithmModelLibrarys(@Valid @RequestBody UpdateTaAlgorithmModelLibrarysDTO updateRaServerTypes) {
        var loginUser = SecurityUtils.getLoginUser();
        var userDTO = new LoginUserDTO();
        userDTO.setUsername(loginUser.getUsername());
        return iTaService.updateTaAlgorithmModelLibrarys(updateRaServerTypes,userDTO);
    }
    @ApiOperation(value = "添加任务类型")
    @OperationLogAnnotation(getModuleName = ModuleEnum.TK_CODE,getOperationAction = OperationActionEnum.SAVE)
    @PostMapping("/v1/taTaskTypes")
    @CustomResponse
    public RootResponse createTaTaskTypes(@Valid @RequestBody CreateTaTaskTypesDTO createMajorDTO) {
        var loginUser = SecurityUtils.getLoginUser();
        var userDTO = new LoginUserDTO();
        userDTO.setUsername(loginUser.getUsername());
        return iTaService.createTaTaskTypes(createMajorDTO,userDTO);
    }
    @ApiOperation(value = "查询任务类型")
    @GetMapping("/v1/taTaskTypes")
    @CustomResponse
    public RootResponse selectTaTaskTypes(@Valid TaTaskTypesPageDTO serverAreaPageDTO) {
        return iTaService.selectTaTaskTypes(serverAreaPageDTO);
    }

    @ApiOperation(value = "删除任务类型")
    @OperationLogAnnotation(getModuleName = ModuleEnum.TK_CODE,getOperationAction = OperationActionEnum.UPDATE)
    @DeleteMapping("/v1/taTaskTypes")
    @CustomResponse
    public RootResponse deleteTaTaskTypes(@NotBlank(message = "Id不能为空") @RequestParam(value = "id") String id) {
        var loginUser = SecurityUtils.getLoginUser();
        var userDTO = new LoginUserDTO();
        userDTO.setUsername(loginUser.getUsername());
        return iTaService.deleteTaTaskTypes(id,userDTO);
    }

    @ApiOperation(value = "修改任务类型")
    @OperationLogAnnotation(getModuleName = ModuleEnum.TK_CODE,getOperationAction = OperationActionEnum.UPDATE)
    @PutMapping("/v1/taTaskTypes")
    @CustomResponse
    public RootResponse updateTaTaskTypess(@Valid @RequestBody UpdateTaTaskTypesDTO updateRaServerTypes) {
        var loginUser = SecurityUtils.getLoginUser();
        var userDTO = new LoginUserDTO();
        userDTO.setUsername(loginUser.getUsername());
        return iTaService.updateTaTaskTypes(updateRaServerTypes,userDTO);
    }
    @ApiOperation(value = "查询算法专家知识信息")
    @GetMapping("/v1/taAlgorithmExpertKnowledges")
    @CustomResponse
    public RootResponse selectTaAlgorithmExpertKnowledges(@NotBlank(message = "Id不能为空") @RequestParam(value = "algorithmId") String algorithmId) {
        return iTaService.selectTaAlgorithmExpertKnowledges(algorithmId);
    }
    @ApiOperation(value = "添加算法专家知识信息")
    @OperationLogAnnotation(getModuleName = ModuleEnum.TK_CODE,getOperationAction = OperationActionEnum.SAVE)
    @PostMapping("/v1/taAlgorithmExpertKnowledges")
    @CustomResponse
    public RootResponse createTaAlgorithmExpertKnowledges(@Valid @RequestBody CreateTaAlgorithmExpertKnowledgesDTO createMajorDTO) {
        var loginUser = SecurityUtils.getLoginUser();
        var userDTO = new LoginUserDTO();
        userDTO.setUsername(loginUser.getUsername());
        return iTaService.createTaAlgorithmExpertKnowledges(createMajorDTO,userDTO);
    }

    @ApiOperation(value = "修改任务信息")
    @OperationLogAnnotation(getModuleName = ModuleEnum.TK_CODE,getOperationAction = OperationActionEnum.UPDATE)
    @PutMapping("/v1/taTasks")
    @CustomResponse
    public RootResponse updateTaTasks(@Valid @RequestBody UpdateTaTasksDTO updateRaServerTypes) {
        var loginUser = SecurityUtils.getLoginUser();
        var userDTO = new LoginUserDTO();
        userDTO.setUsername(loginUser.getUsername());
        return iTaService.updateTaTasks(updateRaServerTypes,userDTO);
    }

    @ApiOperation(value = "添加任务信息")
    @OperationLogAnnotation(getModuleName = ModuleEnum.TK_CODE,getOperationAction = OperationActionEnum.SAVE)
    @PostMapping("/v1/taTasks")
    @CustomResponse
    public RootResponse createTaTasks(@Valid @RequestBody CreateTaTasksDTO createMajorDTO) {
        var loginUser = SecurityUtils.getLoginUser();
        var userDTO = new LoginUserDTO();
        userDTO.setUsername(loginUser.getUsername());
        return iTaService.createTaTasks(createMajorDTO,userDTO);
    }
    @ApiOperation(value = "查询任务信息")
    @GetMapping("/v1/taTasks")
    @CustomResponse
    public RootResponse selectTaTasks(@Valid TaTasksPageDTO serverAreaPageDTO) {
        var loginUser = SecurityUtils.getLoginUser();
        serverAreaPageDTO.setAreaId(loginUser.getArea().get(0).getAreaId());
        return iTaService.selectTaTasks(serverAreaPageDTO);
    }

    @ApiOperation(value = "删除任务信息")
    @OperationLogAnnotation(getModuleName = ModuleEnum.TK_CODE,getOperationAction = OperationActionEnum.UPDATE)
    @DeleteMapping("/v1/taTasks")
    @CustomResponse
    public RootResponse deleteTaTasks(@NotBlank(message = "Id不能为空") @RequestParam(value = "id") String id) {
        var loginUser = SecurityUtils.getLoginUser();
        var userDTO = new LoginUserDTO();
        userDTO.setUsername(loginUser.getUsername());
        return iTaService.deleteTaTasks(id,userDTO);
    }
    @ApiOperation(value = "查询任务结果信息")
    @GetMapping("/v1/taTasksResult")
    @CustomResponse
    public RootResponse selectTaTasksResult(@Valid TaTasksResultPageDTO serverAreaPageDTO) {
        var loginUser = SecurityUtils.getLoginUser();
        serverAreaPageDTO.setAreaId(loginUser.getArea().get(0).getAreaId());
        return iTaService.selectTaTasksResult(serverAreaPageDTO);
    }
}
